/*window.onloaded = function() {
	setTimeout(function(){
        $("#popupLoginSelect").popup("open");
   },1000);
}*/
(function () {
	$(document).ready(function() {
		/*jQuery('#loadingImage').hide();*/
		/*$("#popupLoginSelect").popup();
		$("#popupLoginSelect").popup('open');*/
		/*$("#goHome").attr("href",$("#goHome").attr("href")+"&&identify="+$('#identify').val());*/
		
		//$("#popupLoginSelectTrigger").trigger("click"); 
	});
    ///用户登录
    jQuery('#subtnForUser').on('click', function () {
		    var name = jQuery("#user").val();
			var password =jQuery("#pwd").val();
			var smsCode =jQuery("#smsCode").val();
			var identify = jQuery("#identify").val();
			var urladress =jQuery("#url").val();
				var url = window.rootPath + '/ui/login/msubmit';
				jQuery("input").attr("disabled", true);
				jQuery(".login").attr("disabled", true);
				jQuery(".set").attr("disabled", true);
				
				
				$("#popupWait").popup();
        		$("#popupWait").popup('open');
				/*jQuery('#loadingImage').show();*/
				var data = {
					"accountName" : name,
					"password" : sha256_digest(password),
					"smsCode" : smsCode
				}
				jQuery.ajax({
					url : encodeURI(url),
					type : "post",
					dataType : "json",
					data : JSON.stringify(data),
					contentType : "application/json;charset=UTF-8",
					success : function(data) {
						jQuery("input").attr("disabled", false);
						jQuery(".login").attr("disabled", false);
						jQuery(".set").attr("disabled", false);
						/*jQuery('#loadingImage').hide();*/
						$("#popupWait").popup('close');
						if (data.code == 0) {
							jQuery('#error').html('用户名或密码错误');
							/*createCode();
							jQuery("#loginCode").val('');*/
						} else if (data.code == 1) {
							/*var picture = data.picture;
							localStorage.setItem('picture', picture);
							localStorage.setItem('name', name);
							localStorage.setItem('userId', data.userId);	*/	
							
							window.location = window.rootPath + urladress+"?device=mobile&&identify="+identify;
						}
						else if (data.code == 3) {
						
							/*message(data.message);*/
						}
						else if(data.code == 99){//验证码失败
							/*jQuery('#error').html(data.message);*/
						}
					}
				});
    });
    
    $(document).on("pagecreate","#pageOne",function(){   
        setTimeout(function(){
             $("#popupLoginSelect").popup("open");
        },1000);
    });
    
  ///游客登录
    jQuery('#subtnForVisitors').on('click', function () {
		    var name = "Visitors";
			var password ="visitors";
			var smsCode =jQuery("#smsCode").val();
			var identify = jQuery("#identify").val();
			var urladress =jQuery("#url").val();
				var url = window.rootPath + '/ui/login/msubmit';
				jQuery("input").attr("disabled", true);
				jQuery(".login").attr("disabled", true);
				jQuery(".set").attr("disabled", true);
				
				
				$("#popupWait").popup();
        		$("#popupWait").popup('open');
				/*jQuery('#loadingImage').show();*/
				var data = {
					"accountName" : name,
					"password" : sha256_digest(password),
					"smsCode" : smsCode
				}
				jQuery.ajax({
					url : encodeURI(url),
					type : "post",
					dataType : "json",
					data : JSON.stringify(data),
					contentType : "application/json;charset=UTF-8",
					success : function(data) {
						jQuery("input").attr("disabled", false);
						jQuery(".login").attr("disabled", false);
						jQuery(".set").attr("disabled", false);
						/*jQuery('#loadingImage').hide();*/
						$("#popupWait").popup('close');
						if (data.code == 0) {
							jQuery('#error').html('用户名或密码错误');
							/*createCode();
							jQuery("#loginCode").val('');*/
						} else if (data.code == 1) {
							/*var picture = data.picture;
							localStorage.setItem('picture', picture);
							localStorage.setItem('name', name);
							localStorage.setItem('userId', data.userId);	*/	
							
							window.location = window.rootPath + urladress+"?device=mobile&&identify="+identify;
						}
						else if (data.code == 3) {
						
							/*message(data.message);*/
						}
						else if(data.code == 99){//验证码失败
							/*jQuery('#error').html(data.message);*/
						}
					}
				});
    });
})();